package com.wman;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;

import com.wman.sheep.common.utils.DensityUtil;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * @ProjectName: wman
 * @Package: com.wman
 * @ClassName: MeshDrawable
 * @Description: java类作用描述
 * @Author: wman
 * @CreateDate: 2019/11/11 16:11
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/11/11 16:11
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MeshDrawable extends Drawable {
    private final static int INTERVAL = DensityUtil.dip2px(80);
    Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    {
        mPaint.setColor(Color.RED);
        mPaint.setStrokeWidth(DensityUtil.dip2px(2));
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        for (int i = 0; i < getBounds().right; i += INTERVAL) {
            for (int j = 0; j < getBounds().bottom; j += INTERVAL) {
                canvas.drawLine(getBounds().left, j, getBounds().right, j, mPaint);
                canvas.drawLine(i, getBounds().top, i, getBounds().bottom, mPaint);
            }
        }
    }

    @Override
    public void setAlpha(int i) {
        mPaint.setAlpha(i);
    }

    @Override
    public void setColorFilter(@Nullable ColorFilter colorFilter) {
        mPaint.setColorFilter(colorFilter);
    }

    @Override
    public int getOpacity() {
        return mPaint.getAlpha() == 0 ? PixelFormat.TRANSPARENT :
                mPaint.getAlpha() == 0xFF ? PixelFormat.OPAQUE : PixelFormat.TRANSLUCENT;
    }
}
